package com.tms.test;

import com.zebra.remoting.RemotingServer;
import com.zebra.remoting.RpcCodec;
import com.zebra.remoting.ZebraRpcServer;
import com.zebra.remoting.protocol.CommandModelManager;
import com.zebra.remoting.protocol.ZebraCodec;

public class TmsServer {



    RemotingServer   server;

    TmsCommandHandler testCommandHandler = new TmsCommandHandler();
    RpcCodec rpcCodec = new ZebraCodec();

    public TmsServer() {
        // 1. create a Rpc server with port assigned
        server = new ZebraRpcServer();
        // 2. add processor for connect and close event if you need
        server.registerRpcCodec(rpcCodec);
        server.registerCommandHandler(testCommandHandler);
        // 3. register user processor for client request
        // 4. server start
        if (server.start(8989)) {
            System.out.println("server start ok!");
        } else {
            System.out.println("server start failed!");
        }
        System.out.println("==============================");
        // server.getRpcServer().stop();
    }

    public static void main(String[] args) throws Exception {
        CommandModelManager.initializeCommandCode(TestCommandCode.getMap());
        TmsServer ts = new TmsServer();
//        TimeUnit.MILLISECONDS.sleep(60000);
//        ts.server.stop();
    }
}
